package com.zzty.train.pjm.util;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties;

public class EmailUtil {
    private Logger logger = LoggerFactory.getLogger(EmailUtil.class);
    private Properties p=new Properties();
    public String sendEmail(String newEmail,String emailContent,String userName) {
        System.out.println(newEmail+userName+emailContent);
        String result = "success";
        HtmlEmail email = new HtmlEmail();
        email.setHostName("smtp.qq.com"); // 设定smtp服务器
        email.setAuthentication("1612951945@qq.com", "bstdylgpphckfcff"); // 设定smtp服务器的认证资料信息
        try {
            email.addTo(newEmail, userName); // 设定收件人
            email.setFrom("1612951945@qq.com", "自在天原");
            email.setSubject("欢迎来到自在天原！");
            email.setCharset("UTF-8");
            email.setHtmlMsg("您本次的验证码为:"+emailContent);
            email.send();
        } catch (EmailException e) {
            e.printStackTrace();
        }
        return result;
    }
}
